package com.gitee.fsadmin.controller.sys;

import com.gitee.fsadmin.common.context.UserContext;
import com.gitee.fsadmin.common.resp.Result;
import com.gitee.fsadmin.controller.sys.param.SysUserRoleSettingParam;
import com.gitee.fsadmin.service.sys.SysUserRoleService;
import org.noear.solon.annotation.Inject;
import org.noear.solon.validation.annotation.Validated;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Post;

import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Controller;

import java.util.List;

/**
 * @author 六如
 */
@Controller
@Mapping("sys/userrole")
public class SysUserRoleController {

    @Inject
    private SysUserRoleService sysUserRoleService;

    /**
     * 获取用户角色id
     *
     * @return 返回角色id
     */
    @Get @Mapping("/getUserRoleIds")
    public Result<List<Long>> getUserRoleIds(Long userId) {
        List<Long> roleIds = sysUserRoleService.listUserRoleIds(userId);
        return Result.ok(roleIds);
    }

    /**
     * 设置用户角色
     *
     * @param param 表单数据
     * @return 返回影响行数
     */
    @Post @Mapping("/setUserRole")
    public Result<Integer> setUserRole(@Validated  SysUserRoleSettingParam param) {
        sysUserRoleService.setUserRole(param.getUserId(), param.getRoleIds(), UserContext.getUser());
        return Result.ok(1);
    }


}
